<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>用户详情</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/userDetail.css">
</head>
<body>
<div class="container mt-5">
    <h3>用户详情</h3>

    <c:if test="${user == null}">
        <div class="alert alert-danger">未找到该用户</div>
    </c:if>

    <c:if test="${user != null}">
        <table class="table table-bordered">
            <tr>
                <td>用户ID</td>
                <td>${user.id}</td>
            </tr>
            <tr>
                <td>用户名</td>
                <td>${user.loginname}</td>
            </tr>
            <tr>
                <td>姓名</td>
                <td>${user.name}</td>
            </tr>
            <tr>
                <td>邮箱</td>
                <td>${user.email}</td>
            </tr>
            <tr>
                <td>状态</td>
                <td>${user.status == 0 ? '正常' : '禁用'}</td>
            </tr>
            <tr>
                <td>手机号码</td>
                <td>${user.mobilephone}</td>
            </tr>
        </table>

        <h4 class="mt-4">拥有的角色</h4>
        <c:if test="${user.roles == null or empty user.roles}">
            <div class="alert alert-info">该用户未分配角色</div>
        </c:if>

        <c:if test="${user.roles != null and not empty user.roles}">
            <ul class="list-group">
                <c:forEach var="role" items="${user.roles}">
                    <li class="list-group-item">
                            ${role.name}
                        <span class="text-muted"> - ${role.description}</span>
                    </li>
                </c:forEach>
            </ul>
        </c:if>

        <div class="mt-3">
            <a href="${pageContext.request.contextPath}/user/searchPage" class="btn btn-secondary">返回查询</a>
            <a href="${pageContext.request.contextPath}/user/roles?userId=${user.id}" class="btn btn-primary ml-2">修改角色</a>
        </div>
    </c:if>
</div>
</body>
</html>
